home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995…tember: Reference Library / Dev.CD Sep 95 RL / Dev.CD Sep 95 RL.toast / mac / Technical Documentation / develop / develop Issue 22 code / PCI Driver Sample / NCR_DriverProject / Src / GetDeviceLogicalAddress.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-08  |  4.6 KB  |  128 lines  |  [TEXT/MPCC]

  1. /*                                GetDeviceLogicalAddress.c                            */
  2. /*
  3.  * GetDeviceLogicalAddress.c
  4.  * Copyright © 1994-95 Apple Computer Inc. All rights reserved.
  5.  *
  6.  */
  7. /*    .___________________________________________________________________________________.
  8.       | This device retrieves the LogicalAddress and length of a PCI device "register"    |
  9.       | It is independent of the Framework driver. This function may only be called        |
  10.       | from the driver initialization functions.                                            |
  11.       | This may need extension for certain hardware configurations.                        |
  12.     .___________________________________________________________________________________.
  13. */
  14. /*
  15.  * Revised 95.04.07 to use the definitions in PCI.h
  16.  */
  17. #include "NCRDriverPrivate.h" 
  18.  
  19.  
  20. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  21.  * GetDeviceLogicalAddress
  22.  *
  23.  * Retrieve the assigned-address property from the Name Registry and search it for
  24.  * the specified addressSpaceSelector. This function uses the device base register
  25.  * only: it ignores the I/O vs. Memory space selector. It will need modification if
  26.  * the hardware supports 64-bit addressing or needs to understand address spaces.
  27.  */
  28. OSErr
  29. GetDeviceLogicalAddress(
  30.         RegEntryIDPtr            regEntryIDPtr,            /* Driver's Name Registery ID    */
  31.         PCIRegisterNumber        deviceRegister,            /* Register in address property    */
  32.         LogicalAddress            *deviceLogicalAddress,    /* Gets the logical address        */
  33.         ByteCount                *deviceAreaLength        /* Gets the area size            */
  34.     )
  35. {
  36.         OSErr                    status;
  37.         short                    i;                        /* Vector index                    */
  38.         short                    nAddresses;                /* Number of vector elements    */
  39.         RegPropertyValueSize    assignedAddressSize;
  40.         RegPropertyValueSize    logicalAddressSize;
  41.         RegPropertyValue        *assignedAddressProperty; /* Assigned Address property    */
  42.         PCIAssignedAddressPtr    pciAssignedAddressPtr;    /* Assigned Address element ptr    */
  43.         LogicalAddress            *logicalAddressVector;    /* AAPL,addresses property        */
  44.         StringPtr                failureMsg;
  45.         
  46.         Trace(GetDeviceLogicalAddress);
  47.         failureMsg = NULL;
  48.         assignedAddressProperty = NULL;
  49.         logicalAddressVector = NULL;
  50.         if (deviceLogicalAddress == NULL || deviceAreaLength == NULL)
  51.             status = paramErr;
  52.         else {
  53.             /*
  54.              * Fetch the assigned address and AAPL,address properties. Allocate memory
  55.              * for each.
  56.              */
  57.             status = GetThisProperty(
  58.                         regEntryIDPtr,
  59.                         kPCIAssignedAddressProperty,
  60.                         &assignedAddressProperty,
  61.                         &assignedAddressSize
  62.                     );
  63.             CheckStatus(status, "\pNo assigned-addresses property");
  64.             if (status != noErr)
  65.                 failureMsg = "\pNo " kPCIAssignedAddressProperty " property";
  66.         }
  67.         if (status == noErr) {
  68.             status = GetThisProperty(
  69.                         regEntryIDPtr,
  70.                         kAAPLDeviceLogicalAddress,
  71.                         (RegPropertyValue *) &logicalAddressVector,
  72.                         &logicalAddressSize
  73.                     );
  74.             CheckStatus(status, "\pNo AAPL,address property");
  75.             if (status != noErr)
  76.                 failureMsg = "\pNo " kAAPLDeviceLogicalAddress  " property";
  77.         }
  78.         if (status == noErr) {
  79.             status = paramErr;
  80.             nAddresses = assignedAddressSize / sizeof (PCIAssignedAddress);
  81.             pciAssignedAddressPtr = (PCIAssignedAddressPtr) assignedAddressProperty;
  82.             for (i = 0; i < nAddresses; i++, pciAssignedAddressPtr++) {
  83.                 if (GetPCIRegisterNumber(pciAssignedAddressPtr) == deviceRegister) {
  84.                     if (pciAssignedAddressPtr->size.hi != 0            /* 64-bit area?        */
  85.                      || pciAssignedAddressPtr->size.lo == 0) {        /* Zero length        */
  86.                         /*
  87.                          * Open Firmware was unable to assign a valid address to this
  88.                          * memory area. We must return an error to prevent the driver
  89.                          * from starting up. Is there a better error status?
  90.                          */
  91.                         status = paramErr;
  92.                         failureMsg = "\pBad assigned address size";
  93.                         LogHex(
  94.                             pciAssignedAddressPtr->size.hi,
  95.                             "\ppciAssignedAddressPtr->size.hi"
  96.                         );
  97.                         LogHex(
  98.                             pciAssignedAddressPtr->size.lo,
  99.                             "\ppciAssignedAddressPtr->size.lo"
  100.                         );
  101.                     }
  102.                     else if (i >= (logicalAddressSize / sizeof (LogicalAddress))) {
  103.                         /*
  104.                          * The logical address vector is too small -- this is a bug.
  105.                          */
  106.                         status = paramErr;
  107.                         failureMsg = "\pLogical address size < assigned address size"; 
  108.                     }
  109.                     else {
  110.                         status = noErr;
  111.                         *deviceLogicalAddress = logicalAddressVector[i];
  112.                         *deviceAreaLength = pciAssignedAddressPtr->size.lo;
  113.                     }
  114.                     break; /* Exit loop when we find the desired register */
  115.                 }
  116.             }
  117.             CheckStatus(status, "\pNo valid address space");
  118.             if (failureMsg == NULL)
  119.                 failureMsg = "\pAddress space not found";
  120.         }
  121.         DisposeThisProperty(&assignedAddressProperty);
  122.         DisposeThisProperty(&logicalAddressVector);
  123.         if (status != noErr)
  124.             PublishInitFailureMsg(status, failureMsg);
  125.         return (status);
  126. }
  127.  
  128.